<template>
  <div class="app-container">

    <el-table :key="tableKey" v-loading="listLoading" :data="list" border fit highlight-current-row style="width: 100%;">
      <el-table-column label="ID" prop="id" sortable="custom" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.id }}</span>
        </template>
      </el-table-column>
      <el-table-column label="标题" align="center">
        <template slot-scope="scope">
          <span v-html="scope.row.name" />
        </template>
      </el-table-column>

      <el-table-column v-permission="['/bannerNotice/memberDocEdit']" label="操作" width="200" align="center">
        <template slot-scope="scope">
          <div>
            <span v-permission="['/bannerNotice/memberDocEdit']">
              <el-button size="small" type="primary" @click="edit(scope.row)">编辑</el-button>
            </span>
          </div>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog title="编辑公告" :visible.sync="show">
      <el-form>
        <el-form-item label="标题" label-width="70px">
          <el-input v-model="item.name" disabled="true" />
        </el-form-item>

        <el-form-item label="内容" label-width="70px">
          <Tinymce ref="editor" v-model="item.content" :height="400" />
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handle">确 定</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
  import {
    memberDocList,
    memberDocEdit
  } from '@/api/bannerNotice.js'
  import waves from '@/directive/waves'
  import {
    parseTime
  } from '@/utils'
  import Pagination from '@/components/Pagination'
  import permission from '@/directive/permission/index.js'
  import Tinymce from '@/components/Tinymce'

  export default {
    components: {
      Pagination,
      Tinymce
    },
    directives: {
      waves,
      permission
    },
    data() {
      return {
        tableKey: 0,
        list: null,
        listLoading: true,
        total: 0,
        item: {},
        show: false,
      }
    },
    created() {
      this.getList()
    },
    methods: {
      edit(item) {
        this.item = item;
        this.show = true;
      },
      handle() {
        memberDocEdit(this.item).then((res => {
          if (res.code == 20000) {
            this.show = false;
            this.getList();
            setTimeout(() => {
              this.noticeUpdateVisible = true
            }, 0.3 * 1000)
          }
        }))
      },
      getList() {
        this.listLoading = true
        memberDocList(this.listQuery).then(res => {
          if (res.code == 20000) {
            this.list = res.data
            setTimeout(() => {
              this.listLoading = false
            }, 0.3 * 1000)
          } else {
            this.listLoading = true
          }
        })
      },
    }
  }
</script>
